package com.asset.dispoal.business.casedispose.service.command;

import com.asset.dispoal.business.bsCase.domain.db.entity.BsCase;
import com.asset.dispoal.business.bsCase.domain.db.mapper.BsCaseMapper;
import com.asset.dispoal.business.casedispose.dto.CaseDisposeRegisterUpdateRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tech.mhuang.pacebox.core.date.DateTimeUtil;
import tech.mhuang.pacebox.core.ddd.BaseCommand;
import tech.mhuang.pacebox.springboot.core.local.GlobalHeaderThreadLocal;
import tech.mhuang.pacebox.springboot.protocol.Result;

import java.util.Date;

@Component
public class CaseDisposeUpdateRegisterCommand implements BaseCommand<CaseDisposeRegisterUpdateRequest, Result> {

    @Autowired
    BsCaseMapper caseMapper;

    @Override
    public Result execute(CaseDisposeRegisterUpdateRequest request) {
        String userId = GlobalHeaderThreadLocal.get().getUserId();
        Date currentDate = DateTimeUtil.currentDate();
        BsCase bsCase = new BsCase();
        bsCase.setId(request.getId());
        bsCase.setOperateUser(userId);
        bsCase.setOperateTime(currentDate);
        bsCase.setRegisterCaseTime(request.getRegisterTime());
        bsCase.setLitigationNumber(request.getLitigationNumber());
        bsCase.setLitigationAmount(request.getLitigationAmount());
        bsCase.setPreservationAmount(request.getPreservationAmount());
        caseMapper.register(bsCase);
        return Result.ok();
    }
}
